<template>
  <el-backtop :bottom="60"></el-backtop>
  <el-container class="home-container">
    <el-header>
      <div>
        <h1>家族管理系统</h1>
      </div>
      <el-button type="info" @click="dialogVisible = true">{{
        username
      }}</el-button>
    </el-header>
    <el-container>
      <!-- 侧边栏 -->
      <el-aside :width="isCollapse ? '64px' : '200px'">
        <!-- 导航菜单 -->
        <el-menu
          background-color="rgb(62, 77, 105)"
          text-color="white"
          active-text-color="#409eff"
          unique-opened
          :collapse="isCollapse"
          :collapse-transition="false"
          :router="true"
          :default-active="$route.path"
        >
          <el-menu-item index="/welcome" key="0">
            <i class="el-icon-s-home"></i>
            <template #title>主页</template>
          </el-menu-item>
          <el-menu-item
            :index="it.MenuAddress"
            v-for="it in menuList"
            :key="it.MenuId"
          >
            <i class="el-icon-menu"></i>
            <template #title>{{ it.MenuName }}</template>
          </el-menu-item>
        </el-menu>
      </el-aside>

      <!--主体页面-->
      <el-main>
        <!--页面路由占位符-->
        <router-view></router-view>
      </el-main>

    </el-container>
  </el-container>
  
  <el-dialog title="当前用户信息" v-model="dialogVisible" width="40%">
    <el-descriptions title="">
      <el-descriptions-item label="用户名">
        <el-tag size="small">{{ username }}</el-tag>
      </el-descriptions-item>
      <el-descriptions-item label="权限等级">
        <el-tag size="small">{{ level }}</el-tag>
      </el-descriptions-item>
      <el-descriptions-item label="备注">
        <el-tag size="small">{{ remarks }}</el-tag>
      </el-descriptions-item>
    </el-descriptions>
    <template #footer>
      <span class="dialog-footer">
        <el-button type="danger" @click="logout">退出登录</el-button>
        <el-button @click="dialogVisible = false">返回</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script>
export default {
  data() {
    return {
      // 左侧菜单
      menuList: [],
      isCollapse: false,
      dialogVisible: false,
      username: "",
      level: 0,
      remarks: "",
    };
  },
  created() {
    this.username = window.sessionStorage.getItem("username");
    this.level = window.sessionStorage.getItem("level");
    this.remarks = window.sessionStorage.getItem("remarks");
    this.getMenuList();
  },
  methods: {
    logout() {
      window.sessionStorage.clear();
      this.$router.push("/login");
    },
    // 获取导航菜单
    async getMenuList() {
      const { data: res } = await this.$http.get(
        "system/apis/menu?level=" + this.level
      );
      if (res.code != 20000) return this.$message.error("菜单加载失败");
      this.menuList = res.data.menus;
    },
    toggleCollapase() {
      this.isCollapse = !this.isCollapse;
    },
  },
};
</script>

<style lang="less" scoped>
.el-header {
  background-color: rgb(62, 77, 105);
  display: flex;
  justify-content: space-between;
  padding-left: 0%;
  align-items: center;
  color: rgb(184, 184, 184);
  font-size: 30px;

  > div {
    display: flex;
    align-items: center;
    span {
      margin-left: 15px;
    }
  }
}

.el-aside {
  background-color: rgb(62, 77, 105);

  .el-menu {
    border-right: none; 
  }
}

.el-main {
  background-color: #ffffff;
}

.home-container {
  height: 100%;
}

.logo_img {
  width: 40%;
  height: 100%;
}

.iconfont {
  margin-right: 10px;
}

</style>